home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Linux Cubed Series 7: Sunsite
/
Linux Cubed Series 7 - Sunsite Vol 1.iso
/
system
/
emulator
/
bsvc-1.000
/
bsvc-1
/
bsvc-1.0.4
/
src
/
Framework
/
AddressSpace.cxx
next >
Wrap
C/C++ Source or Header
|
1995-07-26
|
6KB
|
237 lines
///////////////////////////////////////////////////////////////////////////////
// $Id: AddressSpace.cxx,v 1.1 1994/02/18 19:47:06 bmott Exp $
///////////////////////////////////////////////////////////////////////////////
// AddressSpace.cxx
//
// This class maintains a list of devices and provides methods to peek and
// poke into them.
//
//
// BSVC "A Microprocessor Simulation Framework"
// Copyright (c) 1993
// By: Bradford W. Mott
// October 31,1993
//
///////////////////////////////////////////////////////////////////////////////
// $Log: AddressSpace.cxx,v $
// Revision 1.1 1994/02/18 19:47:06 bmott
// Initial revision
//
///////////////////////////////////////////////////////////////////////////////
#include "String.h"
#include "BasicCPU.hxx"
#include "BasicDevice.hxx"
#include "AddressSpace.hxx"
///////////////////////////////////////////////////////////////////////////////
// AddressSpace Constructor
///////////////////////////////////////////////////////////////////////////////
AddressSpace::AddressSpace(unsigned long m)
: maximum_address(m)
{
head=tail=(void*)0;
}
///////////////////////////////////////////////////////////////////////////////
// The AddressSpace Destructor
///////////////////////////////////////////////////////////////////////////////
AddressSpace::~AddressSpace()
{
// Destroy all of the devices that are attached to the AddressSpace
while(DetachDevice(0)==1);
}
///////////////////////////////////////////////////////////////////////////////
// Attach a device to the address space (1=OK,0=ERROR)
///////////////////////////////////////////////////////////////////////////////
int AddressSpace::AttachDevice(BasicDevice* device)
{
unsigned long maximum_in_bytes;
maximum_in_bytes=((MaximumAddress()+1) * device->CPU()->Granularity())-1;
if ((device->HighestAddress() >= device->LowestAddress()) &&
(device->HighestAddress() <= maximum_in_bytes) &&
(device->LowestAddress() <= maximum_in_bytes))
{
// Create the new node for the linked list
DeviceNode *p = new DeviceNode;
p->device=device;
p->next=(void*)0;
// Put the node at the end of the linked list
if (tail==(void*)0)
{
head=tail=p;
}
else
{
tail->next=p;
tail=p;
}
return(1);
}
else
{
// Couldn't attach device so delete it!
delete device;
return(0);
}
}
///////////////////////////////////////////////////////////////////////////////
// Detach a device from the address space and destory it (1=OK,0=ERROR)
///////////////////////////////////////////////////////////////////////////////
int AddressSpace::DetachDevice(unsigned int index)
{
DeviceNode *p,*q;
// Make sure it's a valid index
if (index>=NumberOfAttachedDevices())
return(0);
q=(void*)0;
p=head;
for(int t=0;(t<index) && (p!=(void*)0);++t)
{
q=p;
p=p->next;
}
if (p!=(void*)0)
{
// Unlink the DeviceNode
if((p==head) && (p==tail))
{
head=tail=(void*)0;
}
else if (p==head)
{
head=p->next;
}
else if(p==tail)
{
q->next=(void*)0;
tail=q;
}
else
{
q->next=p->next;
}
// Free the device and the device node
delete p->device;
delete p;
return(1);
}
else
{
return(0);
}
}
///////////////////////////////////////////////////////////////////////////////
// Reset all the attached devices
///////////////////////////////////////////////////////////////////////////////
void AddressSpace::Reset()
{
DeviceNode *p;
for(p=head;p!=(void*)0;p=p->next)
p->device->Reset();
}
///////////////////////////////////////////////////////////////////////////////
// Return the number of devices attached to the address space
///////////////////////////////////////////////////////////////////////////////
int AddressSpace::NumberOfAttachedDevices()
{
DeviceNode *p;
int t=0;
for(p=head;p!=(void*)0;p=p->next)
++t;
return(t);
}
///////////////////////////////////////////////////////////////////////////////
// Get device information for the indexed device (return 1=OK,0=ERROR)
///////////////////////////////////////////////////////////////////////////////
int AddressSpace::GetDeviceInformation(int index,
AddressSpaceDeviceInformation& info)
{
DeviceNode *p;
// Make sure it's a valid index
if(index>=NumberOfAttachedDevices())
return(0);
p=head;
for(int t=0;(t<index) && (p!=(void*)0);++t)
p=p->next;
if(p!=(void*)0)
{
info.name=p->device->Name();
info.initialization_arguments=p->device->InitializationArguments();
info.index=index;
return(1);
}
return(0);
}
///////////////////////////////////////////////////////////////////////////////
// Peek a location in the address space
///////////////////////////////////////////////////////////////////////////////
int AddressSpace::Peek(unsigned long addr,unsigned char& c)
{
DeviceNode* p;
// Find the correct device
for(p=head;p!=(void*)0;p=p->next)
if (p->device->CheckMapped(addr))
break;
// Did we find a device
if(p!=(void*)0)
{
// Get the byte
c=p->device->Peek(addr);
return(1);
}
else
{
// No device found BUS ERROR, dude!!!
return(0);
}
}
///////////////////////////////////////////////////////////////////////////////
// Poke a location in the address space
///////////////////////////////////////////////////////////////////////////////
int AddressSpace::Poke(unsigned long addr, unsigned char c)
{
DeviceNode* p;
// Find the correct device
for(p=head;p!=(void*)0;p=p->next)
if (p->device->CheckMapped(addr))
break;
// Did we find a device
if(p!=(void*)0)
{
// Store the byte
p->device->Poke(addr,c);
return(1);
}
else
{
// No device found BUS ERROR, dude!!!
return(0);
}
}